package cn.mumzone.pos.model.source;


import java.util.HashMap;

import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.net.source.AbsRepository;
import cn.mumzone.basic.util.RxUtil;
import cn.mumzone.pos.api.ApiRequest;
import cn.mumzone.pos.model.MemberEntity;
import cn.mumzone.pos.model.SettleCalculatePriceEntity;
import cn.mumzone.pos.model.SettleDiscountAreaEntity;
import cn.mumzone.pos.model.SettleResultEntity;
import retrofit2.Response;

/**
 * Created by lijiateng on 2018/12/12.
 */

public class SettleRepository extends AbsRepository {

    /**
     * 获取会员基本信息
     *
     * @param phone
     * @param callBack
     */
    public void getMemberInfo(String phone, ApiCallBack<MemberEntity> callBack) {
        ApiRequest.getSettleService()
                .getMemberInfo(phone)
                .compose(RxUtil.<Response<BaseResponse<MemberEntity>>>applySchedulers())
                .subscribe(callBack);
    }

    /**
     * 计算结账页面右上角商品金额信息
     *
     * @param settleMap
     * @param callBack
     */
    public void calculateGoodsPrice(HashMap<String, String> settleMap, ApiCallBack<SettleCalculatePriceEntity> callBack) {
        ApiRequest.getSettleService()
                .getGoodsAmount(settleMap)
                .compose(RxUtil.<Response<BaseResponse<SettleCalculatePriceEntity>>>applySchedulers())
                .subscribe(callBack);
    }

    /**
     * 获取结账页面左下角优惠券信息
     *
     * @param requestMap
     * @param callBack
     */
    public void getDiscountAreaInfo(HashMap<String, String> requestMap, ApiCallBack<SettleDiscountAreaEntity> callBack) {
        ApiRequest.getSettleService()
                .getDiscountAreaInfo(requestMap)
                .compose(RxUtil.<Response<BaseResponse<SettleDiscountAreaEntity>>>applySchedulers())
                .subscribe(callBack);
    }

    /**
     * 结账接口
     *
     * @param settleJson
     * @param callBack
     */
    public void getSettleResultInfo(HashMap<String, String> settleJson, ApiCallBack<SettleResultEntity> callBack) {
        ApiRequest.getSettleService()
                .getSettleResult(settleJson)
                .compose(RxUtil.<Response<BaseResponse<SettleResultEntity>>>applySchedulers())
                .subscribe(callBack);
    }

    /**
     * 商米结账回调接口
     *
     * @param settleJson
     * @param callBack
     */
    public void payCallBackToPhysicalStore(HashMap<String, String> settleJson, ApiCallBack<SettleResultEntity> callBack) {
        ApiRequest.getSettleService()
                .payCallBackToPhysicalStore(settleJson)
                .compose(RxUtil.<Response<BaseResponse<SettleResultEntity>>>applySchedulers())
                .subscribe(callBack);
    }

    /**
     * 获取抹零限额
     *
     * @param callBack
     */
    public void getEraseCeilingAmount(ApiCallBack<String> callBack) {
        ApiRequest.getSettleService()
                .getEraseCeiling()
                .compose(RxUtil.<Response<BaseResponse<String>>>applySchedulers())
                .subscribe(callBack);
    }

    /**
     * 清空购物车
     *
     * @param shopId
     * @param callBack
     */
    public void clearGoodsCart(String shopId, ApiCallBack<String> callBack) {
        ApiRequest.getSettleService()
                .clearGoodsCart(shopId)
                .compose(RxUtil.<Response<BaseResponse<String>>>applySchedulers())
                .subscribe(callBack);
    }


    /**
     * 生成积分换购账单
     *
     * @param requestMap
     * @param callBack
     */
    public void saveOrderIntegral(HashMap<String, String> requestMap, ApiCallBack<String> callBack) {
        ApiRequest.getSettleService()
                .saveOrderIntegral(requestMap)
                .compose(RxUtil.<Response<BaseResponse<String>>>applySchedulers())
                .subscribe(callBack);
    }

    /**
     * 查询订单状态
     * @param orderId
     * @param callBack
     */
    public void querySmPayOrderInfo(String orderId, ApiCallBack<SettleResultEntity> callBack) {
        ApiRequest.getSettleService()
                .querySmPayOrderInfo(orderId)
                .compose(RxUtil.<Response<BaseResponse<SettleResultEntity>>>applySchedulers())
                .subscribe(callBack);
    }
}
